package edu.tum.in.campar.twodui.studentcanteen;

import java.util.ArrayList;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import edu.tum.in.campar.twodui.studentcanteen.model.DailyMenu;
import edu.tum.in.campar.twodui.studentcanteen.model.DataProvider;
import edu.tum.in.campar.twodui.studentcanteen.model.Meal;

public class SLMealDetailActivity extends ListActivity {
	protected ArrayList<Meal> meals;
	protected DailyMenu menu;
	protected int index;
	protected ArrayList<DailyMenu> menus;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
        ListView list = getListView();
        menus = DataProvider.get().getData();
        index = getIntent().getIntExtra("day", 0);
        
        if (menus.size() <= index)
        	index = 0;
        
        //TODO: handle empty data
        if (menus.size() != 0){
	        menu = menus.get(index);
	        meals = menu.getMeals();
        }else{
        	menu = new DailyMenu("");
        	meals = new ArrayList<Meal>();
        }
        
        list.setAdapter(new ArrayAdapter<Meal>(this, android.R.layout.simple_list_item_2, meals)
        {
        	@Override
        	public boolean isEnabled(int position) {
        		return false;
        	}
        	
        	@Override
        	public View getView(int position, View convertView, ViewGroup parent) {
        		View v = getLayoutInflater().inflate(android.R.layout.simple_list_item_2, null);
    			TextView text = (TextView)v.findViewById(android.R.id.text1);
    			text.setText(meals.get(position).getTitle());
    			
    			text = (TextView)v.findViewById(android.R.id.text2);
    			text.setText(meals.get(position).getPrice() + "\u20AC");
    			text.setGravity(Gravity.RIGHT);
    			
        		return v;
        	}
        });
	}
	
	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);
		
		
	}
}
